package com.yaorange.jxc.goods.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yaorange.jxc.goods.entity.GoodsType;
import com.yaorange.jxc.goods.mapper.GoodsTypeMapper1;

import com.yaorange.jxc.goods.service.GoodsTypeService1;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @description:
 * @company: yaorange
 * @author: wu YanZu
 * @version: 1.0
 * @create: 2022-04-27 15:34:27
 */
@Service
public class GoodsTypeServiceImpl1 implements GoodsTypeService1 {
    @Autowired
    private GoodsTypeMapper1 goodsTypeMapper;

    @Override
    public List<GoodsType> findGoodsTypeList() {

        List<GoodsType> typeList = goodsTypeMapper.selectTypeList();
        for (GoodsType type:typeList
             ) {
            Integer goodsTypeId = type.getGoodsTypeId();
            QueryWrapper<GoodsType> goodsTypeQueryWrapper = new QueryWrapper<>();
            goodsTypeQueryWrapper.eq("p_id",goodsTypeId);
            List<GoodsType> goodsTypeList = goodsTypeMapper.selectList(goodsTypeQueryWrapper);
            type.setChildrenList(goodsTypeList);

            List<GoodsType> childrenList = type.getChildrenList();
            for (GoodsType children:childrenList
            ) {
                Integer goodsTypeId1 = children.getGoodsTypeId();
                QueryWrapper<GoodsType> goodsTypeQueryWrapper1 = new QueryWrapper<>();
                goodsTypeQueryWrapper1.eq("p_id",goodsTypeId1);
                List<GoodsType> goodsTypeList1 = goodsTypeMapper.selectList(goodsTypeQueryWrapper1);
                children.setChildrenList(goodsTypeList1);
            }

        }


        return typeList;
    }
}
